package com.managerProvider.controller;

import com.alibaba.fastjson.JSON;
import com.managerProvider.service.RoleService;
import entity.ResponseMessage;
import entity.Role;
import entity.Ur;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * The type Role controller.
 */
@RestController
@RequestMapping("/role")
@CrossOrigin
public class RoleController {
    @Autowired
    private RoleService roleService;

    private Logger logger = Logger.getLogger(this.getClass());

    /**
     * Find all role string.
     *
     * @param role the role
     * @return the string
     */
    @RequestMapping("/findAllRole")
    public String findAllRole(@RequestBody Role role) {
        logger.info("RoleController findAllRole params:" + role);
        ResponseMessage msg = roleService.selectAllRole(role);
        logger.info("RoleController findAllRole params:" + role + ",result:" + msg);
        return JSON.toJSONString(msg);
    }

    /**
     * Insert role string.
     *
     * @param role the role
     * @return the string
     */
    @RequestMapping("/insertRole")
    public String insertRole(@RequestBody Role role) {
        logger.info("RoleController insertRole params:" + role);
        ResponseMessage msg = roleService.insertRole(role);
        logger.info("RoleController insertRole params:" + role + ",result:" + msg);
        return JSON.toJSONString(msg);
    }

    /**
     * Update role string.
     *
     * @param role the role
     * @return the string
     */
    @RequestMapping("/updateRole")
    public String updateRole(@RequestBody Role role) {
        logger.info("RoleController updateRole params:" + role);
        ResponseMessage msg = roleService.updateRole(role);
        logger.info("RoleController updateRole params:" + role + ",result:" + msg);
        return JSON.toJSONString(msg);
    }

    /**
     * Insert ur string.
     *
     * @param ur the ur
     * @return the string
     */
    @RequestMapping("/insertUr")
    public String insertUr(Ur ur) {
        logger.info("RoleController insertUr params:" + ur);
        ResponseMessage msg = roleService.insertUr(ur);
        logger.debug("RoleController insertUr params:" + ur + ",result:" + msg);
        return JSON.toJSONString(msg);
    }

    /**
     * 选择角色和权限
     *
     * @param role 角色
     * @return {@link String}
     */
    @RequestMapping("/selectRoleAndPower")
    public String selectRoleAndPower(@RequestBody Role role) {
        logger.info("RoleController selectRoleAndPower params:" + role);
        ResponseMessage msg = roleService.selectRoleAndPower(role);
        logger.debug("RoleController selectRoleAndPower params:" + role + ",result:" + msg);
        return JSON.toJSONString(msg);
    }

    /**
     * 选择一个角色权限
     *
     * @param role 角色
     * @return {@link String}
     */
    @RequestMapping("/selectOneRolePower")
    public String selectOneRolePower(@RequestBody Role role) {
        logger.info("RoleController selectOneRolePower params:" + role);
        ResponseMessage msg = roleService.selectOneRolePower(role);
        logger.debug("RoleController selectRoleAndPower params:" + role + ",result:" + msg);
        return JSON.toJSONString(msg);
    }
}
